Vue.component('yl-goods', {
  template: `<el-dialog id="ylGoods"  title="订单查询" :visible.sync="visibleDialog" width="80vw" :close-on-click-modal="false">
      <el-form :inline="true" :form="form">
          <el-form-item>
            <el-select disabled v-model="Supplier_SerialNumber" placeholder="请选择" style="width: 100%" @change="gyhandleChange">
              <el-option v-for="item in Supplier" :key="item.Supplier_SerialNumber" :label="item.Supplier_Name"
              :value="item.Supplier_SerialNumber"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="Activity_SerialNumber" placeholder="请选择活动名称" style="width: 100%"
              @change="hdhandleChange">
              <el-option v-for="item in iJSONArray_hdmc" :key="item.Activity_SerialNumber" :label="item.Activity_Name"
                :value="item.Activity_SerialNumber"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="Article_SerialNumber" filterable placeholder="请选择商品名称" style="width: 100%">
              <el-option v-for="item in iJSONArray_article_info" :key="item.Article_SerialNumber"
                :label="item.Article_Name" :value="item.Article_SerialNumber">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker style="width: 100%" prefix-icon="el-icon-date" v-model="form.Sales_Date"
              clearable type="datetimerange" :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd" format="yyyy-MM-dd" range-separator="至"
              start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-select v-model="Member_SerialNumber" placeholder="请选择下单人" style="width: 100%">
              <el-option v-for="item in iJSONArray_member_info" :key="item.Member_SerialNumber"
                :label="item.Member_Name" :value="item.Member_SerialNumber"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input v-model.trim="form.phone" clearable placeholder="请输入下单人手机号" />
          </el-form-item>
          <el-form-item>
            <el-input v-model.trim="form.Sales_Order_SerialNumber" clearable placeholder="订单编号/订单明细编号" />
          </el-form-item>
          <el-form-item>
            <el-select v-model="value" placeholder="请选择订单状态" style="width: 100%">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="success" @click="onSerach">查询</el-button>
          </el-form-item>
      </el-form>
      <el-table :data="tableData.slice((form.page-1)*form.limit,form.page*form.limit)" stripe border
        height="calc(100vh - 500px)" :row-key="row=>row.Sales_Order_Detail_SerialNumber"
        @selection-change="handleSelectionChange" style="width: 100%">
        <el-table-column align="center" type="selection" :reserve-selection="true" width="45"></el-table-column>
        <el-table-column align="center" type="index" label="序号" width="50"></el-table-column>
        <el-table-column align="center" prop="Sales_Order_SerialNumber" width="250" show-overflow-tooltip label="订单编号"></el-table-column>
        <el-table-column align="center" prop="Activity_Name" width="300" show-overflow-tooltip label="活动名称"></el-table-column>
        <el-table-column align="center" prop="Sales_Date" width="180" show-overflow-tooltip label="日期"></el-table-column>
        <el-table-column align="center" prop="Member_Nike" width="150" show-overflow-tooltip label="下单人"></el-table-column>
        <el-table-column align="center" prop="Sales_Address" width="300" show-overflow-tooltip label="下单地址"></el-table-column>
        <el-table-column align="center" prop="Sales_Phone" width="300" show-overflow-tooltip label="下单手机号"></el-table-column>
        <el-table-column align="center" prop="name" width="150" show-overflow-tooltip label="订单状态">
          <template slot-scope="scope">
            {{ scope.row.Row_Status == 2 ? '发货' : '签收' }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="Supplier_Name" width="150" show-overflow-tooltip label="供应商"></el-table-column>
        <el-table-column align="center" prop="Article_Name" width="300" show-overflow-tooltip label="商品名称"></el-table-column>
        <el-table-column align="center" prop="Quantity" width="80" show-overflow-tooltip label="数量"></el-table-column>
        <el-table-column align="center" prop="Purchase_Unit_Price" width="150" show-overflow-tooltip label="一件代发单价（元）"></el-table-column>
        <el-table-column align="center" width="150" show-overflow-tooltip label="一件代发总价（元）">
          <template slot-scope="scope">
            {{ scope.row.Purchase_Unit_Price * scope.row.Quantity }}
          </template>
        </el-table-column>
        <!--<el-table-column align="center" width="300" label="实际对账金额（元）">
          <template slot-scope="scope">
            <el-input-number v-model="scope.row.paymentableamount" :min="scope.row.Purchase_Unit_Price * scope.row.Quantity" :step="1" label="描述文字"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="Note" width="180" show-overflow-tooltip label="备注">
          <template slot-scope="scope">
            <el-input v-model="scope.row.Note" size="small"></el-input> 
          </template>
        </el-table-column>-->
        <el-table-column align="center" prop="Sales_Unit_Price" width="150" show-overflow-tooltip label="平台单价"></el-table-column>
        <el-table-column align="center" prop="Amount" width="150" show-overflow-tooltip label="平台总价"></el-table-column>
        <el-table-column align="center" prop="Activity_Unit_Price" width="150" show-overflow-tooltip label="活动单价"></el-table-column>
        <el-table-column align="center" prop="name" width="150" show-overflow-tooltip label="活动总价">
          <template slot-scope="scope">
            {{ scope.row.Activity_Unit_Price * scope.row.Quantity }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="Amount" width="300" show-overflow-tooltip label="付款总价">
          <template v-slot="{row}">
            {{accMul(row.paymentableamount,row.Quantity)}}
          </template>
        </el-table-column>
      </el-table>
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="form.page" :page-sizes="[10, 30 , 60 ,100, 200, 300, 400]" :page-size="form.limit"
          layout="total, sizes, prev, pager, next, jumper" :total="tableData.length">
      </el-pagination>
      <span slot="footer" class="dialog-footer">
          <el-button @click="$emit('update:visible',false)">取消</el-button>
          <el-button type="primary" @click="submit()">确定</el-button>
      </span>
  </el-dialog>`,
  props: ['data', 'id', 'visible'],
  data() {
    return {
      visibleDialog: false,
      tableData: [],//详情
      iJSONArray_article_info: [],
      form: {
        Open_ID: "",
        phone: "",
        SQLSerialNumber: "P_business_sales_order_detail2",
        Condition: "",
        ExtensionCondition: "",
        // Supplier_SerialNumber: [],
        Sales_Order_SerialNumber: "",
        Sales_Date: null,
        limit: 20,
        page: 1,
      },
      Supplier: [],
      Supplier_SerialNumber: '',
      multipleSelection: [],
      Activity_SerialNumber: '',
      Article_SerialNumber: '',
      Member_SerialNumber: '',
      iJSONArray_member_info: '',
      iJSONArray_hdmc: [],
      options: [
        {
          value: "3",
          label: "签收",
        },
        {
          value: "2",
          label: "发货",
        },
      ],
      value: "",
      sjje: "",
      min: "",
    }
  },
  watch: {
    visible() {
      this.visibleDialog = this.visible
    },
    visibleDialog(val) {
      this.$emit('update:visible', val);
      if (val) {
        this.Supplier_SerialNumber = this.id
        this.tableData = [];
        this.gyhandleChange();
      }
    },
  },
  methods: {
    onSerach(formName) {
      if (this.form.Sales_Date == null) {
        this.$message.error("请选择日期");
        return
      }
      this.form.Supplier_SerialNumber = this.Supplier_SerialNumber;
      this.form.start = this.form.Sales_Date[0];
      this.form.end = this.form.Sales_Date[1];
      this.form.pid = this.form.Sales_Order_SerialNumber;
      this.form.Article_SerialNumber = this.Article_SerialNumber;
      this.form.status = this.value;
      this.form.Activity_SerialNumber = this.Activity_SerialNumber;
      let lArray = new Array();
      lArray.push(this.form);
      const _this = this;
      $.ajax({
        headers: {
          AccessToken: getCookie("token"),
        },
        contentType: "application/json", // 设置请求体的媒体类型为application/json
        // headers: requestHeaders(),
        type: "post",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        //500
        url: "https://service.kdddy.cn/hnx/Get/RequestDetailByJia1",
        data: JSON.stringify(lArray),
        success: function (Result) {
          console.log(_this.data);
          console.log(Result);
          _this.tableData = Result.Data.filter(i => !_this.data.some(j => j.Sales_Order_Detail_SerialNumber == i.Sales_Order_Detail_SerialNumber));
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
    },
    handleCurrentChange(val) {
      this.form.page = val;
    },
    hdhandleChange(value) {
      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/hnx/getArticle/BySupplierID",
        data: {
          id: this.Supplier_SerialNumber,
          aid: value,
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_article_info = Result.Data;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    gyhandleChange(value) {
      const _this = this;
      //活动
      $.ajax({
        headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/hnx/get/Activity",
        data: {
          sid: this.Supplier_SerialNumber,
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_hdmc = Result.Data;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      //商品
      $.ajax({
        // headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/hnx/getArticle/BySupplierID",
        data: {
          id: this.Supplier_SerialNumber,
          aid: "",
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_article_info = Result.Data;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    xdr() {
      const _this = this;
      // return
      $.ajax({
        headers: requestHeaders(),
        type: "post",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service2.essp.top/hnx/generalBusiness/generalQueryByTableName",
        // url: "http://192.168.10.3:8082/generalBusiness/generalQueryByTableName",

        data: {
          Data: "business_member_info", //表名
          Condition: "",
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_member_info = Result;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    cgys() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service2.essp.top/hnx/generalBusiness/generalQueryByTableName",
        data: {
          Data: "business_supplier_info", //表名
          Condition: "Row_Status='0'",
        },
        success: function (Result) {
          console.log(Result);
          _this.Supplier = Result;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    submit() {
      if (this.multipleSelection.length > 0) {
        this.$emit('success', this.multipleSelection)
        this.$emit('update:visible', false)
      } else {
        this.$message({
          type: "warning",
          message: '请选择订单后再确认',
        })
      }
    }
  },
  mounted() {
    this.cgys();
    this.xdr();
  },
})
new Vue({
  el: "#app",
  data() {
    return {
      Member_SerialNumber: "",
      iJSONArray_member_info: [],
      Purchase_Name: "",
      Activity_SerialNumber: "",
      dialogFormVisible: false,
      formLabelWidth: "120px",
      Supplier_SerialNumber: "",
      Supplier: [],
      Article_SerialNumber: "",
      iJSONArray_article_info: [],
      iJSONArray_hdmc: [],
      options: [
        {
          value: "3",
          label: "签收",
        },
        {
          value: "2",
          label: "发货",
        },
      ],
      value: "",
      sjje: "",
      min: "",
      form: {
        Open_ID: "",
        phone: "",
        SQLSerialNumber: "P_business_sales_order_detail2",
        Condition: "",
        ExtensionCondition: "",
        // Supplier_SerialNumber: [],
        Sales_Order_SerialNumber: "",
        Sales_Date: null,
        limit: 20,
        page: 1,
      },
      // rules: {
      //   Supplier_SerialNumber: [
      //     { required: true, message: "请选择供应商", trigger: "change" },
      //   ],
      // },
      Supplier: [],
      tableData: [], //表格数据
      tableData1:[],
      loading: false,
      multipleSelection: [],
      isSupplier: false,
      business_purchase_order: {},
      dialogVisible: false
    };
  },
  mounted() {
    const Purchase_Order_SerialNumber = sessionStorage.getItem("Purchase_Order_SerialNumber");
    console.log(Purchase_Order_SerialNumber);
    this.getData(Purchase_Order_SerialNumber);
    this.cgys();
    this.xdr();
    // this.gthd();
    // this.cspName();
    if (getCookie("role")) {
      this.isSupplier = true;
      let roleObj = JSON.parse(getCookie("role"));
      this.form.Supplier_SerialNumber = [roleObj.other];
      this.Supplier_SerialNumber = roleObj.other
      console.log(roleObj);
      this.gyhandleChange()
    }
  },
  computed: {
    Type() {
      return function (str) {
        switch (str) {
          case "0":
            return "待发货";
          case "1":
            return "发货中";
          case "2":
            return "已发货";
          default:
            return "";
        }
      };
    },
  },
  methods: {
    getOrder(arr) {
      this.tableData = [...this.tableData, ...arr]
    },
    getData(PrimaryKey) {
      const that = this;
      console.log(PrimaryKey);
      $.ajax({
        headers: requestHeaders1(),
        url: `${BASE_URL1}/generalGetDataStructure`,
        type: "POST",
        data: {
          Data: JSON.stringify({ business_purchase_order: { business_purchase_order_detail: {} } }),
          PrimaryKey,
          Condition: JSON.stringify({ base_system_user_role: "Row_Status<>'99'" }),
          Original: '1'
        },
        success: function (res) {
          console.log(res);
          if (res.Status == 'success') {
            const { business_purchase_order } = res.Data;
            that.Purchase_Name = business_purchase_order[0].Purchase_Name
            that.business_purchase_order = business_purchase_order[0];
            //查询订单
            let str = "";
            business_purchase_order[0].Children.business_purchase_order_detail.forEach(item => {
              if (str) {
                str = str + "OR business_purchase_order_detail.Purchase_Order_SerialNumber='" + item.Purchase_Order_SerialNumber + "'\r\n";
              } else {
                str = "business_purchase_order_detail.Purchase_Order_SerialNumber='" + item.Purchase_Order_SerialNumber + "'\r\n";
              }
            })
            $.ajax({
              headers: requestHeaders(),
              url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumber`,
              type: "POST",
              data: {
                SQLSerialNumber: 'A_business_purchase_order_detail1',
                Condition: '',
                ExtensionCondition: window.btoa(unescape(encodeURIComponent("and (" + str + ")"))),
              },
              success: function (Result) {
                that.tableData1 = Result;
                that.tableData = Result;
              },
              complete: function (XMLHttpRequest) {
                requestPretreatment(XMLHttpRequest);
              },
              dataType: "json",
            })
          }
        },
        dataType: "json",
      });
    },
    //下单人
    xdr() {
      const _this = this;
      // return
      $.ajax({
        headers: requestHeaders(),
        type: "post",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service2.essp.top/hnx/generalBusiness/generalQueryByTableName",
        // url: "http://192.168.10.3:8082/generalBusiness/generalQueryByTableName",

        data: {
          Data: "business_member_info", //表名
          Condition: "",
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_member_info = Result;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    cgys() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        type: "POST",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service2.essp.top/hnx/generalBusiness/generalQueryByTableName",
        data: {
          Data: "business_supplier_info", //表名
          Condition: "Row_Status='0'",
        },
        success: function (Result) {
          console.log(Result);
          _this.Supplier = Result;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    qd() {
      if (this.multipleSelection.length > 0) {
        this.dialogFormVisible = false;
        let Purchase_Amount = 0;
        this.multipleSelection.forEach(item => {
          Purchase_Amount = accAdd(Purchase_Amount, item.paymentableamount);
        })
        this.business_purchase_order.Row_Status = '99';
        this.business_purchase_order.Purchase_Amount = Purchase_Amount;

        //订单明细删除
        this.business_purchase_order.Children.business_purchase_order_detail.forEach(item => {
          if (!this.multipleSelection.some(i => i.Sales_Order_Detail_SerialNumber == item.Sales_Order_Detail_SerialNumber)) {
            item.Row_Status = '99';
          }
        })

        //更新
        this.multipleSelection.forEach(item => {
          if (this.business_purchase_order.Children.business_purchase_order_detail.some(i => i.Sales_Order_Detail_SerialNumber == item.Sales_Order_Detail_SerialNumber)) {
            let obj = this.business_purchase_order.Children.business_purchase_order_detail.filter(i => i.Sales_Order_Detail_SerialNumber == item.Sales_Order_Detail_SerialNumber)[0];
            obj.Notes = item.Notes;
            obj.Amount = item.paymentableamount;
          }
        })

        //新增
        this.multipleSelection.forEach(item => {
          if (!this.business_purchase_order.Children.business_purchase_order_detail.some(i => i.Sales_Order_Detail_SerialNumber == item.Sales_Order_Detail_SerialNumber)) {
            this.business_purchase_order.Children.business_purchase_order_detail.push({
              Purchase_Order_Detail_SerialNumber: "",
              Purchase_Order_SerialNumber: this.business_purchase_order.Purchase_Order_SerialNumber,
              Unit_Price_SerialNumber: item.Execute_Unit_Price_SerialNumber,
              Sales_Order_Detail_SerialNumber: item.Sales_Order_Detail_SerialNumber,
              Supplier_Article_SerialNumber: item.Supplier_Article_SerialNumber,
              Purchase_Unit_Price: item.Purchase_Unit_Price,
              Quantity: item.Quantity,
              Receipt_Quantity: 0,
              Not_Receipt_Quantity: 0,
              Shippment_Quantity: 0,
              Inventory_Quantity: 0,
              Purchase_Amount: accMul(item.Quantity, item.Purchase_Unit_Price),
              Notes: item.Note,
              Amount: item.paymentableamount,
            });
          }
        })
        const { add, modify } = this.deal()
        let data = {}
        if (add == null) {
          data = {
            Data: JSON.stringify({
              Modify: { business_purchase_order: [modify] },

            })
          }
        } else {
          data = {
            Data: JSON.stringify({
              Modify: { business_purchase_order: [modify] },
              Add: { business_purchase_order: [add],}
            }),
          }
        }
        const that = this;
        $.ajax({
          headers: requestHeaders(),
          url: `${BASE_URL2}/generalBusiness/generalSave`,
          type: 'POST',
          data,
          success: function (res) {
            if (res.Status === 'success') {
              that.$message.success("提交成功")
              window.location.href = 'index.html';
            } else {
              that.$message.error("提交失败，请稍后再试")
            }
          },
          complete: function (XMLHttpRequest) {
            that.loading = false;
            requestPretreatment(XMLHttpRequest);//config/config.js 响应预检
          },
          dataType: "json"
        })
      } else {
        this.$message({
          type: "warning",
          message: '请选择订单后再确认',
        })
      }
    },
    deal() {
      const add = deepClone(this.business_purchase_order);
      const modify = deepClone(this.business_purchase_order);

      let add_business_purchase_order_detail = [], modify_business_purchase_order_detail = [];
      for (const i in modify.Children.business_purchase_order_detail) {
        const obj = modify.Children.business_purchase_order_detail[i];
        if (!Object.keys(obj).some(item => item.includes('_Original'))) {
          add_business_purchase_order_detail.push(obj)
        } else {
          modify_business_purchase_order_detail.push(obj)
        }
      }

      add.Children.business_purchase_order_detail = add_business_purchase_order_detail;
      modify.Children.business_purchase_order_detail = modify_business_purchase_order_detail;

      if (add_business_purchase_order_detail.length == 0 && modify_business_purchase_order_detail.length == 0) {
        return { add: null, modify };
      }

      return { add, modify };
    },
    //活动名称查商品
    hdhandleChange(value) {
      console.log(value);
      console.log(this.Supplier_SerialNumber);

      const _this = this;
      $.ajax({
        // headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/hnx/getArticle/BySupplierID",
        data: {
          id: this.Supplier_SerialNumber,
          aid: value,
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_article_info = Result.Data;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    //供应商查活动And商品
    gyhandleChange(value) {
      console.log(value, "gyhandleChange");
      console.log(this.Supplier_SerialNumber);
      console.log(this.Article_SerialNumber);
      const _this = this;
      //活动
      $.ajax({
        headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/hnx/get/Activity",
        data: {
          sid: this.Supplier_SerialNumber,
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_hdmc = Result.Data;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
      //商品
      $.ajax({
        // headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        url: "https://service.kdddy.cn/hnx/getArticle/BySupplierID",
        data: {
          id: this.Supplier_SerialNumber,
          aid: "",
        },
        success: function (Result) {
          console.log(Result);
          _this.iJSONArray_article_info = Result.Data;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    handleChange(value) {
      console.log(value, "value");
      const _this = this;

      $.ajax({
        headers: requestHeaders(),
        type: "get",
        // url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        // url: "https://service.kdddy.cn/hnx/get/SupplierInfo",
        url: "https://service.kdddy.cn/hnx/getArticle/BySupplierID",
        data: {
          id: value, //表名
          aid: "",
        },
        success: function (Result) {
          console.log(Result);
          _this.Supplier = Result.Data;
        },
        complete: function (XMLHttpRequest) {
          //   requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    chaxun() {
      if (this.Activity_SerialNumber) {
        this.tableData = this.tableData1.filter(i=>i.Activity_SerialNumber == this.Activity_SerialNumber)
      }
      if (this.Article_SerialNumber) {
        this.tableData = this.tableData1.filter(i=>i.Article_SerialNumber == this.Article_SerialNumber)
      }
      if (this.Member_SerialNumber) {
        this.tableData = this.tableData1.filter(i=>i.Member_SerialNumber == this.Member_SerialNumber)
      }
      if (this.form.phone) {
        this.tableData = this.tableData1.filter(i=>i.Sales_Phone == this.form.phone)
      }
      if (this.form.Sales_Order_SerialNumber) {
        this.tableData = this.tableData1.filter(i=>i.Sales_Order_SerialNumber == this.form.Sales_Order_SerialNumber)
      }
      if (this.form.Sales_Order_SerialNumber) {
        this.tableData = this.tableData1.filter(i=>i.Sales_Order_SerialNumber == this.form.Sales_Order_SerialNumber)
      }
    },
    onSerach(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.form.PaginationNumber = 1;
          this.getList(this.form);
        } else {
          this.$message({
            message: "请选择供应商",
            type: "warning",
          });
          return false;
        }
      });
    },
    handleSelectionChange(val) {
      console.log(val);

      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
    },
    handleCurrentChange(val) {
      this.form.page = val;
    },
    submitForm() {
      this.dialogFormVisible = true;

      //   if (this.multipleSelection.length > 0) {
      //     this.$prompt("请输入对账单名称", "提示", {
      //       confirmButtonText: "确定",
      //       cancelButtonText: "取消",
      //       inputPattern: /^(?!\s*$).{1,50}$/,
      //       inputErrorMessage: "不能为空且长度小于等于50",
      //     })
      //       .then(({ value }) => {
      //         let arr = [];
      //         let sql = "";
      //         this.multipleSelection.forEach((item) => {
      //           if (sql) {
      //             sql =
      //               sql +
      //               "or Sales_Order_Detail_SerialNumber='" +
      //               item.Sales_Order_Detail_SerialNumber +
      //               "' \r\n";
      //           } else {
      //             sql =
      //               "Sales_Order_Detail_SerialNumber='" +
      //               item.Sales_Order_Detail_SerialNumber +
      //               "' \r\n";
      //           }
      //           //修改状态
      //           let Reconciliation_Status = item.Reconciliation_Status.charAt(1);
      //           item.Reconciliation_Status = "1" + Reconciliation_Status;
      //           let is = true;
      //           arr.forEach((obj) => {
      //             if (obj.Supplier_SerialNumber == item.Supplier_SerialNumber) {
      //               //obj.Purchase_Amount = accAdd(obj.Purchase_Amount, accMul(item.Delivery_Quantity, item.Purchase_Unit_Price))  原先
      //               obj.Purchase_Amount = accAdd(
      //                 obj.Purchase_Amount,
      //                 item.Purchase_Amount
      //               );
      //               obj.Children.business_purchase_order_detail.push({
      //                 Purchase_Order_Detail_SerialNumber: "",
      //                 Purchase_Order_SerialNumber: "",
      //                 Unit_Price_SerialNumber:
      //                   item.Execute_Unit_Price_SerialNumber,
      //                 Sales_Order_Detail_SerialNumber:
      //                   item.Sales_Order_Detail_SerialNumber,
      //                 Supplier_Article_SerialNumber:
      //                   item.Supplier_Article_SerialNumber,
      //                 Purchase_Unit_Price: item.Purchase_Unit_Price,
      //                 Quantity: item.Delivery_Quantity,
      //                 Receipt_Quantity: 0,
      //                 Not_Receipt_Quantity: 0,
      //                 Shippment_Quantity: 0,
      //                 Inventory_Quantity: 0,
      //                 Purchase_Amount: item.Purchase_Amount,
      //                 Notes: item.Notes,
      //                 Amount: accMul(
      //                   item.Delivery_Quantity,
      //                   item.Purchase_Unit_Price
      //                 ),
      //               });
      //               is = false;
      //             }
      //           });
      //           if (is) {
      //             //新
      //             arr.push({
      //               Purchase_Order_SerialNumber: "",
      //               Supplier_SerialNumber: item.Supplier_SerialNumber,
      //               Purchase_Date: getYMDHMSDate(),
      //               Transaction_Type: "",
      //               Purchase_Amount: item.Purchase_Amount,
      //               Purchase_Name: value ? value : "",
      //               Paid_Amount: 0,
      //               Apply_Amount: 0,
      //               Confirm_Amount: 0,
      //               Row_Status: this.isSupplier ? "99" : "00",
      //               Children: {
      //                 business_purchase_order_detail: [
      //                   {
      //                     Purchase_Order_Detail_SerialNumber: "",
      //                     Purchase_Order_SerialNumber: "",
      //                     Unit_Price_SerialNumber:
      //                       item.Execute_Unit_Price_SerialNumber,
      //                     Sales_Order_Detail_SerialNumber:
      //                       item.Sales_Order_Detail_SerialNumber,
      //                     Supplier_Article_SerialNumber:
      //                       item.Supplier_Article_SerialNumber,
      //                     Purchase_Unit_Price: item.Purchase_Unit_Price,
      //                     Quantity: item.Delivery_Quantity,
      //                     Receipt_Quantity: 0,
      //                     Not_Receipt_Quantity: 0,
      //                     Shippment_Quantity: 0,
      //                     Inventory_Quantity: 0,
      //                     Purchase_Amount: item.Purchase_Amount,
      //                     Notes: item.Notes,
      //                     Amount: accMul(
      //                       item.Delivery_Quantity,
      //                       item.Purchase_Unit_Price
      //                     ),
      //                   },
      //                 ],
      //               },
      //             });
      //           }
      //         });
      //         $.ajax({
      //           headers: requestHeaders(),
      //           type: "POST",
      //           url: `${BASE_URL2}/generalBusiness/generalQueryByTableNameWithOriginal`,
      //           data: {
      //             Data: "business_sales_order_detail",
      //             Condition: sql,
      //           },
      //           success: function (data) {
      //             data.forEach((item) => {
      //               let Reconciliation_Status =
      //                 item.Reconciliation_Status.charAt(1);
      //               item.Reconciliation_Status = "1" + Reconciliation_Status;
      //             });
      //             $.ajax({
      //               headers: requestHeaders(),
      //               url: `${BASE_URL2}/generalBusiness/generalSave`,
      //               type: "POST",
      //               data: {
      //                 Data: JSON.stringify({
      //                   Add: {
      //                     business_purchase_order: arr,
      //                     base_operation_log: [
      //                       generateLog(
      //                         "采购对账",
      //                         "平台端操作",
      //                         "business_purchase_order",
      //                         JSON.stringify({
      //                           Modify: {
      //                             business_sales_order_detail:
      //                               that.multipleSelection,
      //                           },
      //                           Add: { business_purchase_order: arr },
      //                         })
      //                       ),
      //                     ],
      //                   },
      //                   Modify: { business_sales_order_detail: data },
      //                 }),
      //               },
      //               success: function (res) {
      //                 if (res.Status === "success") {
      //                   that.$message.success("提交成功");
      //                   window.history.go(-1);
      //                 } else {
      //                   that.$message.error("提交失败，请稍后再试");
      //                 }
      //               },
      //               complete: function (XMLHttpRequest) {
      //                 that.loading = false;
      //                 requestPretreatment(XMLHttpRequest);
      //               },
      //               dataType: "json",
      //             });
      //           },
      //           complete: function (XMLHttpRequest) {
      //             requestPretreatment(XMLHttpRequest);
      //           },
      //           dataType: "json",
      //         });
      //       })
      //       .catch(() => {});
      //   } else {
      //     that.$message({
      //       message: "当前没有需要对账的订单明细",
      //       type: "warning",
      //     });
      //   }
    },
    getList(form) {
      //换页方法
      const that = this;
      let data = deepClone(form);
      data.Condition = window.btoa(
        unescape(
          encodeURIComponent(
            "%" +
            data.Sales_Order_SerialNumber +
            "%,%" +
            data.Sales_Order_SerialNumber +
            "%"
          )
        )
      );
      let sql = "";
      if (data.Sales_Date) {
        sql =
          sql +
          "AND business_collection_detail.Collection_Date BETWEEN '" +
          data.Sales_Date[0] +
          "' AND '" +
          data.Sales_Date[1] +
          "'\r\n";
      }
      if (data.Supplier_SerialNumber.length > 0) {
        let str = "";
        data.Supplier_SerialNumber.forEach((item) => {
          if (str) {
            //后续
            str =
              str +
              " OR business_sales_order_detail.Supplier_SerialNumber = '" +
              item +
              "'\r\n";
          } else {
            //首次
            str =
              " business_sales_order_detail.Supplier_SerialNumber = '" +
              item +
              "'\r\n";
          }
        });
        // // 修改后的代码
        // if (Array.isArray(data.Supplier_SerialNumber)) {
        //   data.Supplier_SerialNumber.forEach((item) => {
        //     // 处理逻辑
        //   });
        // } else {
        //   console.error("data.Supplier_SerialNumber 不是一个数组");
        //   // 或者根据具体情况添加其他处理逻辑，如初始化 data.Supplier_SerialNumber 为一个数组
        //   // data.Supplier_SerialNumber = [];
        // }
        sql = sql + "AND (" + str + ") \r\n";
      }
      data.ExtensionCondition = window.btoa(unescape(encodeURIComponent(sql)));
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalQueryBySQLSerialNumberWithOriginal`,
        type: "POST",
        data,
        success: function (Result) {
          Result.forEach((item) => {
            item.Purchase_Amount = accMul(
              item.Delivery_Quantity,
              item.Purchase_Unit_Price
            );
            item.Purchase_Amount_Original = accMul(
              item.Delivery_Quantity,
              item.Purchase_Unit_Price
            );
            item.Notes = "";
            item.Notes_Original = "";
          });
          that.tableData = Result;
          if (Result.length == 0) {
            that.$message({
              message: "未查询到可对账的订单明细",
              type: "warning",
            });
          }
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });
    },
    handleRemove(index) {
      this.$confirm("是否要删除此行?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.tableData = this.tableData.filter(
            (i, id) => id != (this.form.page - 1) * this.form.limit + index
          );
        })
        .catch(() => { });
    },
  },
});
